package javabasic.singleton.ehanshi;


/**
 * 静态代码块创建对象，提供静态方法获取在类加载时由静态代码块创建的对象
 */
public class Singleton03 {
    private static Singleton03 INSTANCE;

    static {
        INSTANCE=new Singleton03();
        //可以在静态代码块中书写逻辑
    }

    //构造方法私有化
    private Singleton03(){}

    public static Singleton03 getInstance(){
        return INSTANCE;
    }

    public static void main(String[] args) {
        Singleton03 instance = Singleton03.getInstance();
        Singleton03 instance1 = Singleton03.getInstance();
        System.out.println(instance==instance1);
    }
}
